import { Injectable, NotFoundException } from '@nestjs/common';
import { ProductDto } from '../dto/product.dto';

@Injectable()
export class ProductService {
  throwGenericError() {
      throw new Error('Method not implemented.');
  }
  throwHttpException() {
      throw new Error('Method not implemented.');
  }
  private readonly products: ProductDto[] = [
    { id: '1', name: '商品 1', price: 100, description: '这是商品 1' },
    { id: '2', name: '商品 2', price: 200, description: '这是商品 2' },
    { id: '3', name: '商品 3', price: 300, description: '这是商品 3' },
  ];

  findAll(): ProductDto[] {
    return this.products;
  }

  findOne(id: string): ProductDto {
    const product = this.products.find(product => product.id === id);
    if (!product) {
      throw new NotFoundException(`商品 ID ${id} 不存在`);
    }
    return product;
  }
}